<%@page import="org.springframework.web.context.request.RequestScope" 
import="java.util.*, koction.model.consumer.*, koction.model.purchaseListBoard.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    
<script type="text/javascript">
	$(function(){
		var purchaseList=$(":checkbox[name=purchaseNo]");
		var str="";
		$("#deletePurchaseList").click(function(){
			str="";
			purchaseList=$(":checkbox[name=purchaseNo]");
			if($(":checkbox[name=purchaseNo]:checked").length==0){
				alert("상품을 선택하세요");
				return false;
			}//if
		if(confirm("선택한 내역을 삭제할까요?")){
			for(var i=0; i<purchaseList.length; i++){
				if(purchaseList[i].checked){
					if(str==""){
						str+="purchaseNo=";
					}else if(str!=""){
						str+="&purchaseNo=";
					}
					str+=$(purchaseList[i]).val();
				}//if
			}//for
			$.ajax({
				type:"post",
				url:"deletePurchaseList.do",
				data:str+"&id=${sessionScope.cvo.id}&pageNo=${requestScope.lvo.pagingBean.nowPage}",
				dataType:"json",
				success:function(jsonData){
					var table="";
					if(jsonData.list.length==0){
							$("#purchaseListDiv").html("구매내역이 없습니다.");
							$("#pageNoDiv").html("");
					}else{
					$.each(jsonData.list, function(index, data){
						table+='<tr><td><input type="checkbox" name="purchaseNo" value='+data.purchaseNo+'></td>'
						+'<td><img src="upload/'+data.productId+'.jpg" width="100" height="50"></td>'
						+'<td><a href="getProductInfo.do?productId="'+data.productId+'>'+data.productName+'</a></td>'
						+'<td>'+data.purchaseAmount+'</td>'
						+'<td>'+data.purchaseDate+'</td>'
						+'</tr>';
						});//each
						$("#purchaseListTbody").html(table);
						var page="";
						if(jsonData.pagingBean.previousPageGroup){
							page+='<a href="getPurchaseList.do?pageNo='+(jsonData.pagingBean.startPageOfPageGroup-1)+'>◀</a>';
						}
						for(var j=jsonData.pagingBean.startPageOfPageGroup; j<=jsonData.pagingBean.endPageOfPageGroup; j++){
							if(jsonData.pagingBean.nowPage!=j){
								page+='<a href="getPurchaseList.do?pageNo='+j+'">'+j+'</a>';}
							else{
								page+=j;}
						}//for
						if(jsonData.pagingBean.nextPageGroup){
							page+='<a href="getPurchaseList.do?pageNo='+(jsonDatapagingBean.endPageOfPageGroup+1)+'>▶</a>';
						}
						$("#pageNoDiv").html(page);
						}//if-else
					}//callback
				});//ajax
			}//confrim
		});//click
	});
</script>
   
   
<%ListVO lvo=(ListVO)request.getAttribute("lvo");%>

	<%if(lvo.getList().size()==0){%>
		구매내역이 없습니다.
	<%}else if(lvo.getList().size()>0){%>
		<div id="purchaseListDiv">
			<table>
			<thead>
				<tr>
					<th></th><th>상품이미지</th><th>상품명</th><th>수량</th><th>구매일</th>
				</tr>
			</thead>
			<tbody id="purchaseListTbody">
			<%for(int i=0; i<lvo.getList().size(); i++){%>
				<tr>
				<td><input type="checkbox" name="purchaseNo" value=<%=lvo.getList().get(i).getPurchaseNo() %>></td>
				<td><img src="upload/<%=lvo.getList().get(i).getProductId() %>.jpg" width="100" height="50"></td>	
				<td><a href="getProductInfo.do?productId=<%=lvo.getList().get(i).getProductId() %>">
							<%=lvo.getList().get(i).getProductName()%></a></td>
				<td><%=lvo.getList().get(i).getPurchaseAmount() %></td>
				<td><%=lvo.getList().get(i).getPurchaseDate() %></td>
				</tr>
			<%} %>
			</tbody>
			</table>
		</div>
	<%}%>
<div id="pageNoDiv">
	<c:if test="${requestScope.lvo.pagingBean.previousPageGroup}">
	 	<a href="getPurchaseList.do?pageNo=${requestScope.lvo.pagingBean.startPageOfPageGroup-1}">◀</a>
	</c:if>
	<c:forEach var="i" begin="${requestScope.lvo.pagingBean.startPageOfPageGroup}" end="${requestScope.lvo.pagingBean.endPageOfPageGroup}">
	 	<c:choose>
	 		<c:when test="${requestScope.lvo.pagingBean.nowPage!=i}">
	 			<a href="getPurchaseList.do?pageNo=${i}">${i}</a>
	 		</c:when>
	 		<c:otherwise>
				${i}
			</c:otherwise>
		</c:choose>
	</c:forEach>	 
	<c:if test="${requestScope.lvo.pagingBean.nextPageGroup}">
	 	<a href="getPurchaseList.do?pageNo=${requestScope.lvo.pagingBean.endPageOfPageGroup+1}">▶</a>
	 </c:if>
</div>
<%if(lvo.getList().size()>0){%>
<input type="button" id="deletePurchaseList" value="구매내역 삭제" class="button">
<%} %>



